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

Interfaéce

23/01/2008
parent 766d66d6
File added

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}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sokoban", "WindowsApplication1\Sokoban.csproj", "{65B7010D-5D30-4535-B221-797D1E8D4FCF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -9,10 +9,10 @@ Global
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
{65B7010D-5D30-4535-B221-797D1E8D4FCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{65B7010D-5D30-4535-B221-797D1E8D4FCF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65B7010D-5D30-4535-B221-797D1E8D4FCF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65B7010D-5D30-4535-B221-797D1E8D4FCF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
File added
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,2,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,2,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);
if (niveau[i, j] == 1)
{
sol[i, j].ImageLocation = (appPath + @"\..\..\Images\sol.png");
}
else
{
sol[i, j].ImageLocation = (appPath + @"\..\..\Images\zone.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];
caisses[id].Location = new System.Drawing.Point((x*2 + _xpos) * _xpas, (y*2 + _ypos) * _ypas);
if (testCaissePlacee(x*2, y*2))
{
caisses[id].ImageLocation = (appPath + @"\..\..\Images\caisse_placee.png");
}
else
{
caisses[id].ImageLocation = (appPath + @"\..\..\Images\caisse.png");
}
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++;
}
personnage.Location = new System.Drawing.Point(_x, _y);
}
public bool testDeplacement(int x, int y)
{
/* 0 = mur
* 1 = sol
* 2 = arrives
*/
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)
{
return true;
}
else
{
return false;
}
}
public bool testCaissePlacee(int x, int y)
{
if (niveau[_ypos + y, _xpos + x] == 2)
{
return true;
}
else
{
return false;
}
}
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment