Commit 936ee29a authored by Zéfling's avatar Zéfling 🎨
Browse files

On voit le personnage, on peut le déplace dans les zones dessines et on l'on...

On voit le personnage, on peut le déplace dans les zones dessines et on l'on peut déplacer une caisse (rouge) à fois.

16/03/2008
parents

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sokoban_Jeu", "Sokoban_Jeu\Sokoban_Jeu.csproj", "{74F6E958-E9E2-40C1-A385-6B376CC7DFB3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{74F6E958-E9E2-40C1-A385-6B376CC7DFB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74F6E958-E9E2-40C1-A385-6B376CC7DFB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74F6E958-E9E2-40C1-A385-6B376CC7DFB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74F6E958-E9E2-40C1-A385-6B376CC7DFB3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
File added
namespace Sokoban_Jeu
{
partial class Form1
{
/// <summary>
/// Variable nécessaire au concepteur.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
/// <param name="disposing">true si les ressources managées doivent être supprimées ; sinon, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Code généré par le Concepteur Windows Form
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.personnage = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.personnage)).BeginInit();
this.SuspendLayout();
//
// personnage
//
this.personnage.BackColor = System.Drawing.Color.Transparent;
this.personnage.Location = new System.Drawing.Point(179, 238);
this.personnage.Name = "personnage";
this.personnage.Size = new System.Drawing.Size(38, 36);
this.personnage.TabIndex = 0;
this.personnage.TabStop = false;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(837, 439);
this.Controls.Add(this.personnage);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.personnage)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox personnage;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Sokoban_Jeu
{
public partial class Form1 : Form
{
public int[,] niveau = new int[,] {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0},
{0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0},
{0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0},
{0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0},
{0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0},
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
public int[,] niveauElements = new int[,] {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
public int _xpas = 25;
public int _ypas = 25;
public int _x = 25;
public int _y = 25;
public int _xpos = 1;
public int _ypos = 1;
public int mouvements = 0;
public String appPath = Application.StartupPath;
public System.Windows.Forms.PictureBox[] caisses;
public Form1()
{
InitializeComponent();
this.KeyPreview = true;
personnage.ImageLocation = (appPath + @"\..\..\Images\perso_gauche.png");
personnage.Location = new System.Drawing.Point(_x, _y);
personnage.BackColor = Color.FromArgb(0, 0, 0, 0);
personnage.Size = new System.Drawing.Size(_xpas, _ypas);
int nombreCaseX = niveau.GetLength(1);
int nombreCaseY = niveau.GetLength(0);
// afficher les caisses
int nombreCaisse = 0;
for (int i = 0; i < nombreCaseY; i++)
{
for (int j = 0; j < nombreCaseX; j++)
{
nombreCaisse += niveauElements[i, j];
if (niveauElements[i, j] > 0)
{
niveauElements[i, j] = nombreCaisse; // on place un identifateur la place
}
}
}
caisses = new System.Windows.Forms.PictureBox[nombreCaisse+1];
int k = 1;
for (int i = 0; i < nombreCaseY; i++)
{
for (int j = 0; j < nombreCaseX; j++)
{
if (niveauElements[i, j] > 0)
{
caisses[k] = new System.Windows.Forms.PictureBox();
caisses[k].Size = new System.Drawing.Size(25, 25);
caisses[k].ImageLocation = (appPath + @"\..\..\Images\caisse.png");
caisses[k].Location = new System.Drawing.Point(j * _ypas, i * _xpas);
Controls.Add(caisses[k]);
k++;
}
}
}
// changer une sol et mur
System.Windows.Forms.PictureBox[,] sol;
sol = new System.Windows.Forms.PictureBox[nombreCaseY,nombreCaseX];
for (int i = 0; i < nombreCaseY; i++)
{
for (int j = 0; j < nombreCaseX; j++)
{
if (niveau[i,j] == 1 )
{
sol[i,j] = new System.Windows.Forms.PictureBox();
sol[i,j].Size = new System.Drawing.Size(25, 25);
sol[i,j].ImageLocation = (appPath + @"\..\..\Images\sol.png");
sol[i,j].Location = new System.Drawing.Point(j*_ypas,i*_xpas);
Controls.Add(sol[i,j]);
}
}
}
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
switch (keyData)
{
case Keys.Right:
deplacement(1, 0);
personnage.ImageLocation = (appPath + @"\..\..\Images\perso_droite.png");
return true;
case Keys.Left:
deplacement(-1, 0);
personnage.ImageLocation = (appPath + @"\..\..\Images\perso_gauche.png");
return true;
case Keys.Up:
deplacement(0, -1);
personnage.ImageLocation = (appPath + @"\..\..\Images\perso_haut.png");
return true;
case Keys.Down:
deplacement(0, 1);
personnage.ImageLocation = (appPath + @"\..\..\Images\perso_bas.png");
return true;
default: return base.ProcessCmdKey(ref msg, keyData);
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
}
public void deplacement(int x, int y)
{
if (testDeplacement(x, y))
{
if (testCaisse(x, y))
{
int id = niveauElements[_ypos + y, _xpos + x];
System.Console.WriteLine(id);
caisses[id].Location = new System.Drawing.Point((x*2 + _xpos) * _xpas, (y*2 + _ypos) * _ypas);
niveauElements[_ypos + 2 * y, _xpos + 2 * x] = niveauElements[_ypos + y, _xpos + x];
niveauElements[_ypos + y, _xpos + x] = 0;
}
_xpos += x;
_ypos += y;
_x += x * _xpas;
_y += y * _ypas;
mouvements++;
}
System.Console.WriteLine(_xpos + " " + _ypos);
System.Console.WriteLine(niveauElements);
personnage.Location = new System.Drawing.Point(_x, _y);
}
public bool testDeplacement(int x, int y)
{
/* 0 = mur
* 1 = sol
* 2 = support
*/
if (niveau[ _ypos + y, _xpos + x] >= 1)
{
// test si il a une caisse
if (!testCaisse(x, y) || (testCaisse(x, y) && !testCaisse(2 * x, 2 * y) && niveau[_ypos + 2 * y, _xpos + 2 * x] >= 1))
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
public bool testCaisse(int x, int y)
{
/* 0 = mur
* 1 = caisse
*/
if (niveauElements[_ypos + y, _xpos + x] >= 1)
{
System.Console.WriteLine("*");
return true;
}
else
{
return false;
}
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Sokoban_Jeu
{
static class Program
{
/// <summary>
/// Point d'entrée principal de l'application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Les informations générales relatives à un assembly dépendent de
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[assembly: AssemblyTitle("Sokoban_Jeu")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("XPSP2")]
[assembly: AssemblyProduct("Sokoban_Jeu")]
[assembly: AssemblyCopyright("Copyright © XPSP2 2008")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
[assembly: ComVisible(false)]
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
[assembly: Guid("dbf331db-204c-43f1-8a12-7556178bf70f")]
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
//
// Version principale
// Version secondaire
// Numéro de build
// Révision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//------------------------------------------------------------------------------
// <auto-generated>
// Ce code a été généré par un outil.
// Version du runtime :2.0.50727.832
//
// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si
// le code est régénéré.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Sokoban_Jeu.Properties
{
/// <summary>
/// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées.
/// </summary>
// Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder
// à l'aide d'un outil, tel que ResGen ou Visual Studio.
// Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen
// avec l'option /str ou régénérez votre projet VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// Retourne l'instance ResourceManager mise en cache utilisée par cette classe.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Sokoban_Jeu.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Remplace la propriété CurrentUICulture du thread actuel pour toutes
/// les recherches de ressources à l'aide de cette classe de ressource fortement typée.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.